<?php

namespace Mlym\CodeGeneration\InitGeneration\Controller;

use EasySwoole\HttpAnnotation\AnnotationController;
use Mlym\CodeGeneration\ClassGeneration\ClassGeneration;
use Mlym\CodeGeneration\InitGeneration\Controller\Method\GetClientIP;
use Mlym\CodeGeneration\InitGeneration\Controller\Method\Index;
use Mlym\CodeGeneration\InitGeneration\Controller\Method\OnException;
use Mlym\CodeGeneration\InitGeneration\Controller\Method\OnRequest;
use Mlym\CodeGeneration\InitGeneration\Controller\Method\WriteJson;

class ControllerGeneration extends ClassGeneration
{
    /**
     * @var $config ControllerConfig
     */
    protected $config;

    public function __construct(?ControllerConfig $config = null)
    {
        if (empty($config)) {
            $config = new ControllerConfig('Base', "App\\HttpController");
            $config->setExtendClass(AnnotationController::class);
        }
        parent::__construct($config);
    }

    function addClassData()
    {
        $this->addGenerationMethod(new Index($this));
        $this->addGenerationMethod(new OnRequest($this));
        $this->addGenerationMethod(new GetClientIP($this));
        $this->addGenerationMethod(new OnException($this));
        $this->addGenerationMethod(new WriteJson($this));
    }
}
